package ru.stepuk.modeller.distributions;

import java.util.HashMap;
import java.util.Map;
import ru.stepuk.modeller.generators.RandomNumberGenerator;

/**
 *
 * @author ivan
 */
public class ErlangDistribution implements Distribution {

    private int shape;
    private double rate;
    private ExponentialDistribution ed;

    public ErlangDistribution(int shape, double rate, RandomNumberGenerator g) {
        if (shape < 1 || rate <= 0) {
            throw new IllegalArgumentException();
        }
        this.shape = shape;
        this.rate = rate;
        //TODO Warning!! check wiki Convolution random number generator
        ed = new ExponentialDistribution(shape / rate, g);

    }

    public double nextValue() {
        double result = 0;
        for (int i = 0; i < shape; i++) {
            result += ed.nextValue();
        }
        return result;
    }

    public Map<String, Object> getParameters() {
        Map<String, Object> res = new HashMap<String, Object>();
        res.put("Shape", shape);
        res.put("Rate", rate);
        return res;
    }

}
